<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    工作年限: <input type="text" class="year"><br>
    薪资: <input type="text" class="money"><br>
    <button>计算年终奖</button>年终奖:<span></span>
    <script>
        var year = document.querySelector('.year')
        var money = document.querySelector('.money')
        var btn = document.querySelector('button')
        var span = document.querySelector('span')
        btn.onclick = function () {
            var a = Number(year.value)
            var b = Number(money.value)
            console.log(a, b);
            if (isNaN(a) || isNaN(b)) {
                alert('输入的内容是非法形式')
                return
            }
            let result = 0
            if (a > 0 && a < 1) {
                if (b > 8000) {
                    result = b * 1.2
                } else {
                    result = b
                }
            } else if (a >= 1 && a < 2) {
                if (b > 10000) {
                    result = b * 1.7
                } else {
                    result = b * 1.5
                }
            } else if (a >= 2) {
                if (b > 12000) {
                    result = b * 3.2
                } else {
                    result = b * 3
                }
            }
            span.innerText = result
        }



    </script>
</body>

</html>